package Example;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ResumeProgram extends JFrame {
    private JLabel nameLabel;
    private JTextField nameTextField;
    private JLabel genderLabel;
    private JRadioButton maleRadioButton;
    private JRadioButton femaleRadioButton;
    private JLabel birthplaceLabel;
    private JComboBox<String> birthplaceComboBox;
    private JLabel educationLabel;
    private JList<String> educationList;
    private JButton submitButton;

    public ResumeProgram() {
        // 设置窗口标题
        setTitle("简历填写");

        // 创建面板
        JPanel panel = new JPanel();
        panel.setLayout(new FlowLayout()); // 使用流式布局

        // 创建姓名标签和文本框
        nameLabel = new JLabel("姓名");
        nameTextField = new JTextField(20); // 设置文本框长度为20个字符

        // 创建性别标签和单选按钮
        genderLabel = new JLabel("性别");
        maleRadioButton = new JRadioButton("男");
        femaleRadioButton = new JRadioButton("女");

        // 将单选按钮添加到一个按钮组
        ButtonGroup genderGroup = new ButtonGroup();
        genderGroup.add(maleRadioButton);
        genderGroup.add(femaleRadioButton);

        // 创建出生地标签和下拉框
        birthplaceLabel = new JLabel("出生地：");
        String[] places = {"北京","上海", "杭州", "南京", "成都"};
        birthplaceComboBox = new JComboBox<>(places);

        // 创建学历标签和列表框
        educationLabel = new JLabel("学历：");
        String[] degrees = {"本科", "硕士", "博士", "博士后"};
        educationList = new JList<>(degrees);
        educationList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // 设置只能选择一个
        JScrollPane scrollPane = new JScrollPane(educationList); // 使用滚动条包装列表框
        scrollPane.setPreferredSize(new Dimension(120, 80)); // 设置滚动条尺寸为120x80

        // 创建提交按钮
        submitButton = new JButton("提交");
        submitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 获取用户填写的信息
                String name = nameTextField.getText();
                String gender = maleRadioButton.isSelected() ? "男" : "女";
                String birthplace = (String) birthplaceComboBox.getSelectedItem();
                String education = educationList.getSelectedValue();

                // 在控制台打印用户填写的信息
                System.out.println("姓名：" + name);
                System.out.println("性别：" + gender);
                System.out.println("出生地：" + birthplace);
                System.out.println("学历：" + education);
            }
        });

        // 将组件添加到面板
        panel.add(nameLabel);
        panel.add(nameTextField);
        panel.add(genderLabel);
        panel.add(maleRadioButton);
        panel.add(femaleRadioButton);
        panel.add(birthplaceLabel);
        panel.add(birthplaceComboBox);
        panel.add(educationLabel);
        panel.add(scrollPane);
        panel.add(submitButton);

        // 设置面板边距
        panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        // 将面板添加到窗口中
        add(panel);

        // 设置窗口关闭按钮默认操作
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // 自动调整窗口大小并可见
        pack();
        setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new ResumeProgram();
            }
        });
    }
}

